package com.lianzhihui.romeex.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.TradeRecordBean;
import com.lianzhihui.romeex.utils.CoinUtils;
import com.lianzhihui.romeex.utils.DateUtil;

import java.util.List;

/**
 * Description: 主页适配器
 * Author: RAMON
 * CreateDate: 2020/11/4 8:10 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class TradeRecordAdapter extends BaseQuickAdapter<TradeRecordBean.DetailBean, BaseViewHolder> {

    String coinName;

    public TradeRecordAdapter(@Nullable List<TradeRecordBean.DetailBean> data) {
        super(R.layout.item_trade_record_layout, data);
    }

    public void setCoinName(String coinName) {
        this.coinName = coinName;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, TradeRecordBean.DetailBean item) {

        String status = item.getTradeTypeStr();
        ImageView icon = helper.getView(R.id.iv_icon);
        Glide.with(mContext).load(CoinUtils.getTransactionTypeIcon(item)).into(icon);

        helper.setText(R.id.item_tv_status, status);

        String s = "";
        if (item.getTransactionType() != 8) {
            if (item.isOut) {
                s = "-";
            } else {
                s = "+";
            }
        }
        if (!TextUtils.isEmpty(this.coinName)) {
            helper.setText(R.id.item_tv_sum, s + item.getAmount() + coinName);
        } else {
            helper.setText(R.id.item_tv_sum, s + item.getAmount() + item.getCoinName());
        }
        //  if (isOut) {
        //                        return "转账成功";
        //                    } else {
        //                        return "收款成功";
        //                    }
        helper.setText(R.id.item_tv_address, item.isIsOut() ? item.targetAddress : item.sourceAddress)

                .setText(R.id.item_tv_date, DateUtil.sec2Date(item.getTimestamp()));
    }
}
